package com.whu.waterworks.action;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;

import com.opensymphony.xwork2.ActionSupport;
import com.whu.waterworks.dto.QualityNonNormolDto;
import com.whu.waterworks.dto.QualityNormolDto;
import com.whu.waterworks.model.QualityNonNormol;
import com.whu.waterworks.model.QualityNormol;
import com.whu.waterworks.model.WaterPlantNorm;
import com.whu.waterworks.service.QualityNonNormService;
import com.whu.waterworks.service.QualityNormolService;
import com.whu.waterworks.service.WaterPlantNormService;

public class GetNonNormRequireDataAction extends ActionSupport{

	/**
	 * @authorzhoululu
	 * @date:2016-04-06 21:14
	 * 根据选择的水厂编码和起止时间，去的已录入的非标准指标数据，并进行修改和删除
	 */
	private static final long serialVersionUID = 1L;
	private String code;
	private String startTime;
	private String endTime;
    private QualityNonNormService qualityNonNormService;
    private ArrayList<QualityNonNormolDto> qualityNonNormols;
	
	public String getNonNormRequireData(){
		System.out.println("code="+code);
		System.out.println("startTime="+startTime);
		System.out.println("endTime="+endTime);
		ArrayList<QualityNonNormol> temp=(ArrayList<QualityNonNormol>) qualityNonNormService.getQualityNonNormols(code, startTime, endTime);
		qualityNonNormols=new ArrayList<QualityNonNormolDto>();
		String str="";
		String str1="";
		try{
			if(null!=temp){
				QualityNonNormolDto dtoFields=new QualityNonNormolDto();
				Field fields[]=dtoFields.getClass().getDeclaredFields();
				Class<? extends QualityNonNormolDto> dtoMethod = dtoFields.getClass();
				Class<? extends QualityNonNormol> method = temp.get(0).getClass();			
				for(int i=0;i<temp.size();++i){
					QualityNonNormolDto dto=new QualityNonNormolDto();				
					for (Field field : fields) {
						str=field.getName();
						if(str.equals("id")){
							dto.setId(temp.get(i).getId());
							continue;
						}
						if (str.equals("waterplantId")) {
							dto.setWaterplantId(temp.get(i).getWaterplantId());
							continue;
						}
						if (str.equals("serialVersionUID")) {						
							continue;
						}
						if (str.equals("time")) {
							dto.setTime(temp.get(i).getTime());
							continue;
						}
						if (str.equals("type")) {
							dto.setType(temp.get(i).getType());
							continue;
						}
						System.out.println("str1="+str);
						str=str.substring(0, 1).toUpperCase()+str.substring(1, str.length()-1);
						System.out.println("str2="+str);
						Method m1 =dtoMethod.getMethod("set"+str+"1",String.class);
						Method m2 =method.getMethod("get"+str+"1");
						Method m3 =method.getMethod("get"+str+"2");
						Method m4 =method.getMethod("get"+str+"3");
						str1=m2.invoke(temp.get(i))+","+m3.invoke(temp.get(i))+","+m4.invoke(temp.get(i));
						str1=str1.replaceAll("null", "无数据");
						m1.invoke(dto, str1);
					}
					/*str=temp.get(i).getDcaxsj1()+","+temp.get(i).getDcaxsj2()+","+temp.get(i).getDcaxsj3();
					dto.setDcaxsj1(str);
					str=temp.get(i).getNrdcgjq1()+","+temp.get(i).getNrdcgjq2()+","+temp.get(i).getNrdcgjq3();
					dto.setDcaxsj1(str);*/
					qualityNonNormols.add(dto);
				}
			}
		}
		catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		
		System.out.println(qualityNonNormols.size());
		return SUCCESS;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getStartTime() {
		return startTime;
	}

	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}

	public String getEndTime() {
		return endTime;
	}

	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public QualityNonNormService getQualityNonNormService() {
		return qualityNonNormService;
	}

	public void setQualityNonNormService(QualityNonNormService qualityNonNormService) {
		this.qualityNonNormService = qualityNonNormService;
	}

	public ArrayList<QualityNonNormolDto> getQualityNonNormols() {
		return qualityNonNormols;
	}

	public void setQualityNonNormols(
			ArrayList<QualityNonNormolDto> qualityNonNormols) {
		this.qualityNonNormols = qualityNonNormols;
	}	
}
